<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.4"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Tiny FTP: ftp_server.c File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">Tiny FTP
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.4 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#define-members">Macros</a> &#124;
<a href="#func-members">Functions</a> &#124;
<a href="#var-members">Variables</a>  </div>
  <div class="headertitle"><div class="title">ftp_server.c File Reference</div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><code>#include &lt;pthread.h&gt;</code><br />
<code>#include &lt;errno.h&gt;</code><br />
<code>#include &lt;stdio.h&gt;</code><br />
<code>#include &lt;ctype.h&gt;</code><br />
<code>#include &lt;stdlib.h&gt;</code><br />
<code>#include &lt;unistd.h&gt;</code><br />
<code>#include &lt;strings.h&gt;</code><br />
<code>#include &lt;string.h&gt;</code><br />
<code>#include &lt;fcntl.h&gt;</code><br />
<code>#include &lt;sys/socket.h&gt;</code><br />
<code>#include &lt;sys/types.h&gt;</code><br />
<code>#include &lt;sys/stat.h&gt;</code><br />
<code>#include &lt;netinet/in.h&gt;</code><br />
<code>#include &lt;arpa/inet.h&gt;</code><br />
<code>#include &lt;time.h&gt;</code><br />
<code>#include &quot;ftp_server.h&quot;</code><br />
<code>#include &quot;config.h&quot;</code><br />
<code>#include &quot;cmd_server.h&quot;</code><br />
</div><div class="textblock"><div class="dynheader">
Include dependency graph for ftp_server.c:</div>
<div class="dyncontent">
<div class="center"><img src="ftp__server_8c__incl.png" border="0" usemap="#aftp__server_8c" alt=""/></div>
<map name="aftp__server_8c" id="aftp__server_8c">
<area shape="rect" title=" " alt="" coords="717,5,815,32"/>
<area shape="rect" title=" " alt="" coords="179,80,263,107"/>
<area shape="rect" title=" " alt="" coords="5,155,73,181"/>
<area shape="rect" title=" " alt="" coords="981,80,1047,107"/>
<area shape="rect" title=" " alt="" coords="1072,80,1143,107"/>
<area shape="rect" title=" " alt="" coords="97,155,168,181"/>
<area shape="rect" title=" " alt="" coords="193,155,267,181"/>
<area shape="rect" title=" " alt="" coords="1167,80,1245,107"/>
<area shape="rect" title=" " alt="" coords="1269,80,1340,107"/>
<area shape="rect" title=" " alt="" coords="292,155,355,181"/>
<area shape="rect" title=" " alt="" coords="379,155,481,181"/>
<area shape="rect" title=" " alt="" coords="506,155,602,181"/>
<area shape="rect" title=" " alt="" coords="722,155,807,181"/>
<area shape="rect" title=" " alt="" coords="831,155,927,181"/>
<area shape="rect" title=" " alt="" coords="952,155,1044,181"/>
<area shape="rect" title=" " alt="" coords="1365,80,1429,107"/>
<area shape="rect" href="ftp__server_8h_source.html" title=" " alt="" coords="1068,155,1168,181"/>
<area shape="rect" href="config_8h_source.html" title=" " alt="" coords="1191,155,1266,181"/>
<area shape="rect" href="cmd__server_8h_source.html" title=" " alt="" coords="592,80,703,107"/>
<area shape="rect" title=" " alt="" coords="626,155,698,181"/>
</map>
</div>
</div><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="define-members" name="define-members"></a>
Macros</h2></td></tr>
<tr class="memitem:a4030f144b22022d7463211b78c592383"><td class="memItemLeft" align="right" valign="top"><a id="a4030f144b22022d7463211b78c592383" name="a4030f144b22022d7463211b78c592383"></a>
#define&#160;</td><td class="memItemRight" valign="bottom"><b>FTP_SERVER</b></td></tr>
<tr class="separator:a4030f144b22022d7463211b78c592383"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ac4d8afc60a6a97fac2ee94e1def2a267"><td class="memItemLeft" align="right" valign="top"><a id="ac4d8afc60a6a97fac2ee94e1def2a267" name="ac4d8afc60a6a97fac2ee94e1def2a267"></a>
#define&#160;</td><td class="memItemRight" valign="bottom"><b>FTP_SERVER_PORT</b>&#160;&#160;&#160;21</td></tr>
<tr class="separator:ac4d8afc60a6a97fac2ee94e1def2a267"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a4590bc240c9d6d928eecc7484553c2e7"><td class="memItemLeft" align="right" valign="top"><a id="a4590bc240c9d6d928eecc7484553c2e7" name="a4590bc240c9d6d928eecc7484553c2e7"></a>
#define&#160;</td><td class="memItemRight" valign="bottom"><b>USER_MODE</b>&#160;&#160;&#160;1</td></tr>
<tr class="separator:a4590bc240c9d6d928eecc7484553c2e7"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aaf7aa7762a0536af133a25d4d2b96be6"><td class="memItemLeft" align="right" valign="top"><a id="aaf7aa7762a0536af133a25d4d2b96be6" name="aaf7aa7762a0536af133a25d4d2b96be6"></a>
#define&#160;</td><td class="memItemRight" valign="bottom"><b>ANONYMOUS_MODE</b>&#160;&#160;&#160;2</td></tr>
<tr class="separator:aaf7aa7762a0536af133a25d4d2b96be6"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:afe95cbf25cb718882af3b270d8444891"><td class="memItemLeft" align="right" valign="top"><a id="afe95cbf25cb718882af3b270d8444891" name="afe95cbf25cb718882af3b270d8444891"></a>
void&#160;</td><td class="memItemRight" valign="bottom"><b>greetings</b> (void)</td></tr>
<tr class="memdesc:afe95cbf25cb718882af3b270d8444891"><td class="mdescLeft">&#160;</td><td class="mdescRight">server的欢迎语。 <br /></td></tr>
<tr class="separator:afe95cbf25cb718882af3b270d8444891"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a4297bbb7ddb30e7cc2c896d127501eb5"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="ftp__server_8c.html#a4297bbb7ddb30e7cc2c896d127501eb5">create_socket</a> (void)</td></tr>
<tr class="memdesc:a4297bbb7ddb30e7cc2c896d127501eb5"><td class="mdescLeft">&#160;</td><td class="mdescRight">创建一个TCP套接字。  <a href="ftp__server_8c.html#a4297bbb7ddb30e7cc2c896d127501eb5">More...</a><br /></td></tr>
<tr class="separator:a4297bbb7ddb30e7cc2c896d127501eb5"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a717154ba6392e7882d105c8878e2b89e"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="ftp__server_8c.html#a717154ba6392e7882d105c8878e2b89e">bind_to_port</a> (struct sockaddr_in server_addr, int sockfd)</td></tr>
<tr class="memdesc:a717154ba6392e7882d105c8878e2b89e"><td class="mdescLeft">&#160;</td><td class="mdescRight">绑定到指定端口上。若绑定不成功，将会直接退出程序。  <a href="ftp__server_8c.html#a717154ba6392e7882d105c8878e2b89e">More...</a><br /></td></tr>
<tr class="separator:a717154ba6392e7882d105c8878e2b89e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a0cc55115a0b678b249e3bc9044f9d79b"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="ftp__server_8c.html#a0cc55115a0b678b249e3bc9044f9d79b">listen_to_port</a> (int sockfd, int backlog)</td></tr>
<tr class="memdesc:a0cc55115a0b678b249e3bc9044f9d79b"><td class="mdescLeft">&#160;</td><td class="mdescRight">使套接字监听本地指定端口。若监听失败，将直接退出。  <a href="ftp__server_8c.html#a0cc55115a0b678b249e3bc9044f9d79b">More...</a><br /></td></tr>
<tr class="separator:a0cc55115a0b678b249e3bc9044f9d79b"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a7ff013fbdf95b96f2d023fec829a0ef5"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="ftp__server_8c.html#a7ff013fbdf95b96f2d023fec829a0ef5">accept_connections</a> (int sock_listen)</td></tr>
<tr class="memdesc:a7ff013fbdf95b96f2d023fec829a0ef5"><td class="mdescLeft">&#160;</td><td class="mdescRight">在当前监听的本地端口，接受来自外部的连接请求。  <a href="ftp__server_8c.html#a7ff013fbdf95b96f2d023fec829a0ef5">More...</a><br /></td></tr>
<tr class="separator:a7ff013fbdf95b96f2d023fec829a0ef5"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a80762bccbf172f3bcc3c6149c6c407c5"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="ftp__server_8c.html#a80762bccbf172f3bcc3c6149c6c407c5">send_message</a> (int socket_control, char *info, char *extra)</td></tr>
<tr class="memdesc:a80762bccbf172f3bcc3c6149c6c407c5"><td class="mdescLeft">&#160;</td><td class="mdescRight">向客户端发送信息。  <a href="ftp__server_8c.html#a80762bccbf172f3bcc3c6149c6c407c5">More...</a><br /></td></tr>
<tr class="separator:a80762bccbf172f3bcc3c6149c6c407c5"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a51e4c16da2d4948788531008dd381d35"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="ftp__server_8c.html#a51e4c16da2d4948788531008dd381d35">recv_message</a> (int socket_control)</td></tr>
<tr class="memdesc:a51e4c16da2d4948788531008dd381d35"><td class="mdescLeft">&#160;</td><td class="mdescRight">接收客户端信息。  <a href="ftp__server_8c.html#a51e4c16da2d4948788531008dd381d35">More...</a><br /></td></tr>
<tr class="separator:a51e4c16da2d4948788531008dd381d35"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a79275ba100d8e41616e85d2640b4ccdb"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="ftp__server_8c.html#a79275ba100d8e41616e85d2640b4ccdb">validate_username</a> (char *username)</td></tr>
<tr class="memdesc:a79275ba100d8e41616e85d2640b4ccdb"><td class="mdescLeft">&#160;</td><td class="mdescRight">验证给出的用户名是否存在。  <a href="ftp__server_8c.html#a79275ba100d8e41616e85d2640b4ccdb">More...</a><br /></td></tr>
<tr class="separator:a79275ba100d8e41616e85d2640b4ccdb"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a05cb29dcebf6f6367e907c50b507177a"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="ftp__server_8c.html#a05cb29dcebf6f6367e907c50b507177a">validate_password</a> (char *password, int mode)</td></tr>
<tr class="memdesc:a05cb29dcebf6f6367e907c50b507177a"><td class="mdescLeft">&#160;</td><td class="mdescRight">验证给出的密码是否匹配用户名。  <a href="ftp__server_8c.html#a05cb29dcebf6f6367e907c50b507177a">More...</a><br /></td></tr>
<tr class="separator:a05cb29dcebf6f6367e907c50b507177a"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a46870c32ba12c8313bcb7664e55c13ca"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="ftp__server_8c.html#a46870c32ba12c8313bcb7664e55c13ca">user_login</a> (int socket_control)</td></tr>
<tr class="memdesc:a46870c32ba12c8313bcb7664e55c13ca"><td class="mdescLeft">&#160;</td><td class="mdescRight">处理用户登入的模块。如果用户没有正确选择以匿名或以帐户模式登录，则一直请求用户输入帐号密码，否则不允许后续操作。  <a href="ftp__server_8c.html#a46870c32ba12c8313bcb7664e55c13ca">More...</a><br /></td></tr>
<tr class="separator:a46870c32ba12c8313bcb7664e55c13ca"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a3e49a1da2caece9751648f488b1519c3"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="ftp__server_8c.html#a3e49a1da2caece9751648f488b1519c3">command_handler</a> (int socket_control)</td></tr>
<tr class="memdesc:a3e49a1da2caece9751648f488b1519c3"><td class="mdescLeft">&#160;</td><td class="mdescRight">反复处理用户端发送的指令。  <a href="ftp__server_8c.html#a3e49a1da2caece9751648f488b1519c3">More...</a><br /></td></tr>
<tr class="separator:a3e49a1da2caece9751648f488b1519c3"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aaf5d9aef5682b7dbbc48cdc1833b74ea"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="ftp__server_8c.html#aaf5d9aef5682b7dbbc48cdc1833b74ea">handle_client_request</a> (int socket_control)</td></tr>
<tr class="memdesc:aaf5d9aef5682b7dbbc48cdc1833b74ea"><td class="mdescLeft">&#160;</td><td class="mdescRight">处理用户的请求，包括登录和命令处理。  <a href="ftp__server_8c.html#aaf5d9aef5682b7dbbc48cdc1833b74ea">More...</a><br /></td></tr>
<tr class="separator:aaf5d9aef5682b7dbbc48cdc1833b74ea"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a0ddf1224851353fc92bfbff6f499fa97"><td class="memItemLeft" align="right" valign="top"><a id="a0ddf1224851353fc92bfbff6f499fa97" name="a0ddf1224851353fc92bfbff6f499fa97"></a>
int&#160;</td><td class="memItemRight" valign="bottom"><b>main</b> (int argc, char *argv[])</td></tr>
<tr class="separator:a0ddf1224851353fc92bfbff6f499fa97"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="var-members" name="var-members"></a>
Variables</h2></td></tr>
<tr class="memitem:abdcbc981b6a34e3bced2044702eb1f2c"><td class="memItemLeft" align="right" valign="top"><a id="abdcbc981b6a34e3bced2044702eb1f2c" name="abdcbc981b6a34e3bced2044702eb1f2c"></a>
<a class="el" href="structMsg.html">Msg</a>&#160;</td><td class="memItemRight" valign="bottom"><b>msg</b></td></tr>
<tr class="separator:abdcbc981b6a34e3bced2044702eb1f2c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a4f06d94960b8db675b7855a790c93efb"><td class="memItemLeft" align="right" valign="top"><a id="a4f06d94960b8db675b7855a790c93efb" name="a4f06d94960b8db675b7855a790c93efb"></a>
struct sockaddr_in server_addr client_addr&#160;</td><td class="memItemRight" valign="bottom"><b>addr_data</b></td></tr>
<tr class="separator:a4f06d94960b8db675b7855a790c93efb"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ab1fb5eb1a13a99ada213f0bcd7700de6"><td class="memItemLeft" align="right" valign="top"><a id="ab1fb5eb1a13a99ada213f0bcd7700de6" name="ab1fb5eb1a13a99ada213f0bcd7700de6"></a>
char&#160;</td><td class="memItemRight" valign="bottom"><b>buffer</b> [MAX_INFO]</td></tr>
<tr class="separator:ab1fb5eb1a13a99ada213f0bcd7700de6"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:af94de09503c48ba86a464e6b24b866d7"><td class="memItemLeft" align="right" valign="top"><a id="af94de09503c48ba86a464e6b24b866d7" name="af94de09503c48ba86a464e6b24b866d7"></a>
char&#160;</td><td class="memItemRight" valign="bottom"><b>local_user</b> [] = &quot;admin&quot;</td></tr>
<tr class="separator:af94de09503c48ba86a464e6b24b866d7"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a1959ae9658902fc8502579dda8063029"><td class="memItemLeft" align="right" valign="top"><a id="a1959ae9658902fc8502579dda8063029" name="a1959ae9658902fc8502579dda8063029"></a>
char&#160;</td><td class="memItemRight" valign="bottom"><b>local_password</b> [] = &quot;123&quot;</td></tr>
<tr class="separator:a1959ae9658902fc8502579dda8063029"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a317593e04243f55ebc5c17e8a9c0bf70"><td class="memItemLeft" align="right" valign="top"><a id="a317593e04243f55ebc5c17e8a9c0bf70" name="a317593e04243f55ebc5c17e8a9c0bf70"></a>
char&#160;</td><td class="memItemRight" valign="bottom"><b>anony_user</b> [] = &quot;anonymous&quot;</td></tr>
<tr class="separator:a317593e04243f55ebc5c17e8a9c0bf70"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a225cc4d96fd727d76775941bbb0dde0f"><td class="memItemLeft" align="right" valign="top"><a id="a225cc4d96fd727d76775941bbb0dde0f" name="a225cc4d96fd727d76775941bbb0dde0f"></a>
char&#160;</td><td class="memItemRight" valign="bottom"><b>anony_password</b> [] = &quot;&quot;</td></tr>
<tr class="separator:a225cc4d96fd727d76775941bbb0dde0f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a18dc7c290b054bb13a75634c1400d58d"><td class="memItemLeft" align="right" valign="top"><a id="a18dc7c290b054bb13a75634c1400d58d" name="a18dc7c290b054bb13a75634c1400d58d"></a>
int&#160;</td><td class="memItemRight" valign="bottom"><b>ftp_data_sock</b></td></tr>
<tr class="separator:a18dc7c290b054bb13a75634c1400d58d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a1ea5d0cb93f22f7d0fdf804bd68c3326"><td class="memItemLeft" align="right" valign="top"><a id="a1ea5d0cb93f22f7d0fdf804bd68c3326" name="a1ea5d0cb93f22f7d0fdf804bd68c3326"></a>
int&#160;</td><td class="memItemRight" valign="bottom"><b>mode</b> = -1</td></tr>
<tr class="separator:a1ea5d0cb93f22f7d0fdf804bd68c3326"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p >Code for ftp server.</p>
<dl class="section author"><dt>Author</dt><dd>sc </dd></dl>
<dl class="section version"><dt>Version</dt><dd>V1.0 </dd></dl>
<dl class="section date"><dt>Date</dt><dd>2022-11-19 </dd></dl>
<dl class="section copyright"><dt>Copyright</dt><dd>GNU Public License V3.0 </dd></dl>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="a7ff013fbdf95b96f2d023fec829a0ef5" name="a7ff013fbdf95b96f2d023fec829a0ef5"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a7ff013fbdf95b96f2d023fec829a0ef5">&#9670;&nbsp;</a></span>accept_connections()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int accept_connections </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>sock_listen</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>在当前监听的本地端口，接受来自外部的连接请求。 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">sock_listen</td><td>监听本地端口的套接字的描述符。 </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>成功则返回套接字描述符，失败则报错并返回-1。 </dd></dl>

</div>
</div>
<a id="a717154ba6392e7882d105c8878e2b89e" name="a717154ba6392e7882d105c8878e2b89e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a717154ba6392e7882d105c8878e2b89e">&#9670;&nbsp;</a></span>bind_to_port()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void bind_to_port </td>
          <td>(</td>
          <td class="paramtype">struct sockaddr_in&#160;</td>
          <td class="paramname"><em>server_addr</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>sockfd</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>绑定到指定端口上。若绑定不成功，将会直接退出程序。 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">server_addr</td><td>要绑定的本地端口 </td></tr>
    <tr><td class="paramname">sockfd</td><td>要执行绑定的套接字 </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a3e49a1da2caece9751648f488b1519c3" name="a3e49a1da2caece9751648f488b1519c3"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a3e49a1da2caece9751648f488b1519c3">&#9670;&nbsp;</a></span>command_handler()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void command_handler </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>socket_control</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>反复处理用户端发送的指令。 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">socket_control</td><td>发送控制信令的套接字描述符。 </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a4297bbb7ddb30e7cc2c896d127501eb5" name="a4297bbb7ddb30e7cc2c896d127501eb5"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a4297bbb7ddb30e7cc2c896d127501eb5">&#9670;&nbsp;</a></span>create_socket()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int create_socket </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>创建一个TCP套接字。 </p>
<dl class="section return"><dt>Returns</dt><dd>成功则返回套接字的描述符，失败则返回-1。 </dd></dl>

</div>
</div>
<a id="aaf5d9aef5682b7dbbc48cdc1833b74ea" name="aaf5d9aef5682b7dbbc48cdc1833b74ea"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aaf5d9aef5682b7dbbc48cdc1833b74ea">&#9670;&nbsp;</a></span>handle_client_request()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void handle_client_request </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>socket_control</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>处理用户的请求，包括登录和命令处理。 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">socket_control</td><td>发送控制信令的套接字描述符。 </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a0cc55115a0b678b249e3bc9044f9d79b" name="a0cc55115a0b678b249e3bc9044f9d79b"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a0cc55115a0b678b249e3bc9044f9d79b">&#9670;&nbsp;</a></span>listen_to_port()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void listen_to_port </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>sockfd</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>backlog</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>使套接字监听本地指定端口。若监听失败，将直接退出。 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">sockfd</td><td>将要进行监听的套接字。 </td></tr>
    <tr><td class="paramname">backlog</td><td>最多允许接收的连接请求数。 </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a51e4c16da2d4948788531008dd381d35" name="a51e4c16da2d4948788531008dd381d35"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a51e4c16da2d4948788531008dd381d35">&#9670;&nbsp;</a></span>recv_message()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int recv_message </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>socket_control</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>接收客户端信息。 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">socket_control</td><td>发送控制信令的套接字描述符。 </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>若接收成功，则返回信息长度；失败则返回-1。 </dd></dl>

</div>
</div>
<a id="a80762bccbf172f3bcc3c6149c6c407c5" name="a80762bccbf172f3bcc3c6149c6c407c5"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a80762bccbf172f3bcc3c6149c6c407c5">&#9670;&nbsp;</a></span>send_message()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void send_message </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>socket_control</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">char *&#160;</td>
          <td class="paramname"><em>info</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">char *&#160;</td>
          <td class="paramname"><em>extra</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>向客户端发送信息。 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">socket_control</td><td>发送控制信令的套接字描述符。 </td></tr>
    <tr><td class="paramname">info</td><td>要发送的信息（通常是预先定义好的RFC标准应答） </td></tr>
    <tr><td class="paramname">extra</td><td>附加信息 </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a46870c32ba12c8313bcb7664e55c13ca" name="a46870c32ba12c8313bcb7664e55c13ca"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a46870c32ba12c8313bcb7664e55c13ca">&#9670;&nbsp;</a></span>user_login()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void user_login </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>socket_control</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>处理用户登入的模块。如果用户没有正确选择以匿名或以帐户模式登录，则一直请求用户输入帐号密码，否则不允许后续操作。 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">socket_control</td><td>发送控制信令的套接字描述符。 </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a05cb29dcebf6f6367e907c50b507177a" name="a05cb29dcebf6f6367e907c50b507177a"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a05cb29dcebf6f6367e907c50b507177a">&#9670;&nbsp;</a></span>validate_password()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int validate_password </td>
          <td>(</td>
          <td class="paramtype">char *&#160;</td>
          <td class="paramname"><em>password</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>mode</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>验证给出的密码是否匹配用户名。 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">password</td><td>客户端输入的密码 </td></tr>
    <tr><td class="paramname">mode</td><td>登录模式 </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>存在则返回登录模式，否则返回-1。 </dd></dl>

</div>
</div>
<a id="a79275ba100d8e41616e85d2640b4ccdb" name="a79275ba100d8e41616e85d2640b4ccdb"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a79275ba100d8e41616e85d2640b4ccdb">&#9670;&nbsp;</a></span>validate_username()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int validate_username </td>
          <td>(</td>
          <td class="paramtype">char *&#160;</td>
          <td class="paramname"><em>username</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>验证给出的用户名是否存在。 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">username</td><td>客户端输入的用户名 </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>存在则返回登录模式，否则返回-1。 </dd></dl>

</div>
</div>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.4
</small></address>
</body>
</html>
